package com.tsp_tux.demo.Controller;

import com.tsp_tux.demo.Entity.RespBean;
import com.tsp_tux.demo.Service.ResourceService;
import com.tsp_tux.demo.Util.easyRespBean;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class ResourceController {

    @Resource
    ResourceService resourceService;

    @GetMapping(value = "/searchResource")
    public RespBean searchResource(String search) {
        if (search != null && !search.equals("")) {
            return resourceService.searchResource(search);
        }
        return easyRespBean.err();
    }

    @GetMapping(value = "/getResourceByRid")
    public RespBean getResourceByRid(int rid) {
        return resourceService.getResourceByRid(rid);
    }

    @GetMapping(value = "/getResourceByAid")
    public RespBean getResourceByAid(int aid) {
        return resourceService.getResourceByAid(aid);
    }

    @GetMapping(value = "/getResourceBySid")
    public RespBean getResourceBySid(int sid) {
        return resourceService.getResourceBySid(sid);
    }
}
